﻿Public Class frmChiTietSach
    Private ms As String
    Private show_fromsach As Boolean = False
    Public Sub ShowFromSach(ByVal ma_sach As String, ByVal ts As String)
        Text = ts
        ms = ma_sach
        cbmasach.Enabled = False
        cbmasach.Text = ma_sach
        show_fromsach = True
        ShowDialog()
    End Sub
    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        clsChiTietSach.ThemS(txtIDSach.Text, cbmasach.Text, txtTinhTrang.Text, cboTrangThai.Text)
        datChiTietSach.DataSource = clsChiTietSach.SachCuaDauSach(cbmasach.Text)
       
    End Sub

    Private Sub frmChiTietSach_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If show_fromsach Then
            datChiTietSach.DataSource = clsChiTietSach.SachCuaDauSach(ms)
        Else
            SetCbBox(cbmasach, "MaSach", "MaSach", clsSach.DanhSachDS)
            datChiTietSach.DataSource = clsChiTietSach.SachCuaDauSach(cbmasach.Text)

        End If
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()

    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        If MsgBox("Bạn có muốn xóa sách có chỉ số  là " & txtIDSach.Text & " không ?", MsgBoxStyle.YesNo, "Thông báo") = DialogResult.Yes Then

            clsChiTietSach.XoaS(txtIDSach.Text)
            datChiTietSach.DataSource = clsChiTietSach.SachCuaDauSach(ms)
        End If

    End Sub

    Private Sub btnLamLai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLamLai.Click
        txtIDSach.Text = ""
        txtTinhTrang.Text = ""

    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        clsChiTietSach.SuaS(txtIDSach.Text, cbmasach.SelectedValue, txtTinhTrang.Text, cboTrangThai.Text)
        datChiTietSach.DataSource = clsChiTietSach.SachCuaDauSach(cbmasach.Text)
    End Sub

    Private Sub cbmasach_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbmasach.SelectedIndexChanged
        datChiTietSach.DataSource = clsChiTietSach.SachCuaDauSach(cbmasach.Text)
    End Sub
End Class